﻿using System.Collections.Generic;
using System.Linq;
using System.Xml.Serialization;

namespace BaseUtils.AppConfig
{
    public class Offset : RootBase
    {
        [XmlElement("offset")]
        public List<OffsetItem> OffsetItems { get; set; }
    }

    public class OffsetItem : RootBase
    {

        [XmlAttribute("address")]
        public string Address { get; set; }

        [XmlAttribute("noun")]
        public bool Noun { get; set; }

        [XmlAttribute("interval")]
        public int Interval { get; set; }

        /// <summary>
        /// 根据 Key 找出地址
        /// </summary>
        /// <param name="OffsetItems"></param>
        /// <param name="Key"></param>
        /// <returns></returns>
        public static OffsetItem GetOffsetByKey(List<OffsetItem> OffsetItems ,string Key) {
            if (OffsetItems==null ||OffsetItems.Count<=0)
            {
                return null;
            }
            return OffsetItems.Where(i => i.Key == Key).FirstOrDefault();
        }
    }
}
